home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / X11 / xmcd-1.4 / xmcd.d / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-10  |  3.7 KB  |  184 lines

  1. /*
  2.  *   xmcd - Motif(tm) CD Audio Player
  3.  *
  4.  *   Copyright (C) 1995  Ti Kan
  5.  *   E-mail: ti@amb.org
  6.  *
  7.  *   This program is free software; you can redistribute it and/or modify
  8.  *   it under the terms of the GNU General Public License as published by
  9.  *   the Free Software Foundation; either version 2 of the License, or
  10.  *   (at your option) any later version.
  11.  *
  12.  *   This program is distributed in the hope that it will be useful,
  13.  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.  *   GNU General Public License for more details.
  16.  *
  17.  *   You should have received a copy of the GNU General Public License
  18.  *   along with this program; if not, write to the Free Software
  19.  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20.  *
  21.  */
  22. #ifndef LINT
  23. static char *_main_c_ident_ = "@(#)main.c    5.2 94/12/28";
  24. #endif
  25.  
  26. #define _XMINC_
  27.  
  28. #include "common.d/appenv.h"
  29. #include "common.d/util.h"
  30. #include "xmcd.d/resource.h"
  31. #include "xmcd.d/widget.h"
  32. #include "xmcd.d/cdfunc.h"
  33. #include "libdi.d/libdi.h"
  34.  
  35.  
  36. /* Global data */
  37. char            *progname;    /* The path name we are invoked with */
  38. bool_t            exit_flag;    /* Flag indicating end of application */
  39. appdata_t        app_data;    /* Options data */
  40. widgets_t        widgets;    /* Holder of all widgets */
  41. pixmaps_t        pixmaps;    /* Holder of all pixmaps */
  42. FILE            *errfp = stderr;/* Error message stream */
  43.  
  44. /* Data global to this module only */
  45. STATIC curstat_t    status;        /* Current CD player status */
  46.  
  47.  
  48. /***********************
  49.  *   public routines   *
  50.  ***********************/
  51.  
  52. /*
  53.  * curstat_addr
  54.  *    Return the address of the curstat_t structure.
  55.  *
  56.  * Args:
  57.  *    Nothing.
  58.  *
  59.  * Return:
  60.  *    Nothing.
  61.  */
  62. curstat_t *
  63. curstat_addr(void)
  64. {
  65.     return (&status);
  66. }
  67.  
  68.  
  69. /***********************
  70.  *  internal routines  *
  71.  ***********************/
  72.  
  73.  
  74. /*
  75.  * usage
  76.  *    Display command line usage syntax
  77.  *
  78.  * Args:
  79.  *    argc, argv
  80.  *
  81.  * Return:
  82.  *    Nothing.
  83.  */
  84. STATIC void
  85. usage(int argc, char **argv)
  86. {
  87.     int    i;
  88.  
  89.     fprintf(errfp, "%s\n", app_data.str_badopts);
  90.     for (i = 1; i < argc; i++)
  91.         fprintf(errfp, "%s ", argv[i]);
  92.  
  93.     fprintf(errfp, "\n\n%s %s [-dev device] [-debug]",
  94.         app_data.str_usage, argv[0]);
  95.  
  96. #if defined(SVR4) && defined(sun)
  97.     /* Solaris 2 volume manager auto-start support */
  98.     fprintf(errfp, " [-c device] [-X] [-o]");
  99. #endif
  100.  
  101.      fprintf(errfp,
  102.         "\n\nStandard Xt Intrinsics and Motif options are supported.\n");
  103. }
  104.  
  105.  
  106. /*
  107.  * main
  108.  *    The main function
  109.  */
  110. void
  111. main(int argc, char **argv)
  112. {
  113.     XtAppContext    app;
  114.     XEvent        ev;
  115.  
  116.     /* Initialize variables */
  117.     progname = argv[0];
  118.     exit_flag = FALSE;
  119.  
  120.     /* Handle some signals */
  121.     signal(SIGINT, onsig);
  122.     signal(SIGHUP, onsig);
  123.     signal(SIGTERM, onsig);
  124.  
  125.     /* Initialize X toolkit */
  126.     widgets.toplevel = XtVaAppInitialize(
  127.         &app,
  128.         "XMcd",
  129.         options, XtNumber(options),
  130.         &argc, argv,
  131.         fallbacks,
  132.         XmNmappedWhenManaged, False,
  133.         NULL
  134.     );
  135.  
  136.     /* Get application options */
  137.     XtVaGetApplicationResources(
  138.         widgets.toplevel,
  139.         (XtPointer) &app_data,
  140.         resources,
  141.         XtNumber(resources),
  142.         NULL
  143.     );
  144.         
  145.     /* Check command line for unknown arguments */
  146.     if (argc > 1) {
  147.         usage(argc, argv);
  148.         exit(1);
  149.     }
  150.  
  151.     /* Create all widgets */
  152.     create_widgets(&widgets);
  153.  
  154.     /* Configure resources before realizing widgets */
  155.     pre_realize_config(&widgets);
  156.  
  157.     /* Display widgets */
  158.     XtRealizeWidget(widgets.toplevel);
  159.  
  160.     /* Configure resources after realizing widgets */
  161.     post_realize_config(&widgets, &pixmaps);
  162.  
  163.     /* Register callback routines */
  164.     register_callbacks(&widgets, &status);
  165.  
  166.     /* Initialize various subsystems */
  167.     cd_init(&status);
  168.  
  169.     /* Start various subsystems */
  170.     cd_start(&status);
  171.  
  172.     /* Make the main window visible */
  173.     XtMapWidget(widgets.toplevel);
  174.  
  175.     /* Event processing loop */
  176.     while (!exit_flag) {
  177.         XtAppNextEvent(app, &ev);
  178.         XtDispatchEvent(&ev);
  179.     }
  180.  
  181.     exit(0);
  182. }
  183.  
  184.